<?php
/**
 * Created by PhpStorm.
 * User: Liu
 * Date: 2023/1/4
 * Time: 15:38
 */

namespace app\admin\model;

use think\Model;

class CompanyHistory extends Model {
    protected $table = 'qa_company_history';
    protected $insert = ['create_time','update_time'];
    protected $update = ['update_time'];

    function addHistory($data){
        $result = self::allowField(true)->create($data);
        if ($result){
            //写入系统日志
            insert_system_log('添加公司历史：' . $result);
            return ['code' => 'suc','msg' => config('msg.add_suc')];
        } else {
            return ['code' => 'err','msg' => config('msg.err_msg')];
        }
    }

    function editHistory($data,$id){
        $result = self::save($data, ['id' => $id]);
        if ($result){
            //写入系统日志
            insert_system_log('编辑公司历史：' . $id);
            return ['code' => 'suc','msg' => config('msg.edit_suc')];
        } else {
            return ['code' => 'err','msg' => config('msg.err_msg')];
        }
    }

    function delHistory($id){
        $result = self::destroy(['id' => $id]);
        if ($result){
            //写入系统日志
            insert_system_log('删除公司历史：' . $id);
            return ['code' => 'suc','msg' => config('msg.del_suc')];
        } else {
            return ['code' => 'err','msg' => config('msg.err_msg')];
        }
    }

    protected function setCreateTimeAttr(){
        return time();
    }

    protected function setUpdateTimeAttr(){
        return time();
    }
}